const path = require('path');
const webpack = require('webpack');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const { paths } = require('@fet/fe-reactcli-webpack-tools/utils');
const { webpackConfig, webpackDllConfig } = require('@fet/fe-reactcli-webpack-tools/webpack/lib/config');

module.exports = (env, argv) => {
  const isProd = argv.mode === 'production';
  const ext = isProd ? 'prd' : 'dev';
  return webpackDllConfig || {
    entry: webpackConfig.dll,
    output: {
      filename: `[name].${ext}.js`,
      path: paths.dllPath,
      library: '[name]'
    },
    optimization: {
      minimize: true
    },
    plugins: [
      new webpack.DllPlugin({
        name: '[name]',
        context: paths.roots,
        path: path.join(paths.staticPath, `js/common/[name].${ext}.manifest.json`),
      })
    ]
  }
}
